<template>
	<view>
		<view class="padding flex flex-direction">
			<view class="cu-form-group margin-lr">
				<view class="title text-bold">
					+86
					<icon-font type="arrowdown" size="14" class="padding-left-xs"></icon-font>
				</view>
				<input type="number" placeholder="请输入手机号" v-model="mobile" />
			</view>
			<view class="cu-form-group margin-lr">
				<view class="title">验证码</view>
				<input type="number" placeholder="请输入验证码" v-model="code" />
				<verfication-code :mobile="mobile" type="resetpassword"></verfication-code>
			</view>
			<view class="cu-form-group margin-lr">
				<view class="title">
					密码
				</view>
				<input type="text" password placeholder="请输入新密码 (6-12位字符)" v-model="password" />
			</view>
			<view class="cu-form-group margin-lr">
				<view class="title">
					确认
				</view>
				<input type="text" password placeholder="请输入新密码 (6-12位字符)" v-model="passwordS" />
			</view>
			<userButton @submitEvent="find">确定</userButton>
		</view>
		<loading :loadModal="loadModal"></loading>
	</view>
</template>

<script>
import verficationCode from '../../components/verfication-code.vue';
import userButton from '@/components/user-button.vue';
var _self; //this容器
export default {
	components: {
		verficationCode,
		userButton
	},
	data() {
		return {
			mobile: '',
			code: '',
			password: '',
			passwordS: '',
			loadModal: false //蒙层
		};
	},
	onLoad() {
		_self = this;
	},
	methods: {
		find() {
			if (_self.$util.checkMobile(_self.mobile) && _self.$util.checkCode(_self.code) && _self.$util.checkPassword(_self.password, _self.passwordS)) {
				const param = {
					mobilePrefix: '+86',
					mobile: _self.mobile,
					verifyCode: _self.code,
					password: _self.password
				};
				_self.loadModal = true;
				_self.$http.httpRequest('user/resetPassword', param, false).then(res => {
					_self.loadModal = false;
					if (res._tranStatus) {
						uni.reLaunch({
							url: 'main'
						});
					} else {
						_self.code = '';
						let errormsg = res._exceptionLocalizedMessage;
						if (errormsg != '验证码错误') {
							//非验证码错误清空所有信息
							_self.password = '';
							_self.passwordS = '';
						}
						_self.$util.msg(errormsg);
					}
				});
			}
		}
	}
};
</script>

<style>
page {
	background-color: #fff;
}
</style>
